﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Enhancements.Rest;
using TestWeb25.Components;

namespace TestWeb25
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //register javascript client for specific type
            WebRestClient.RegisterJSClient(typeof(InfoPreviewHandler));
            WebRestClient.RegisterJSClient(typeof(UserExperienceHandler));

            string url = WebRestClient.GetUrlFunctionCall(typeof(InfoPreviewHandler), "GetExtraInfo", 235432);
            this.urlCallSample.Text = url;
            
            //get javascript reference to call specific method in that type
            this.showExtraInfo.NavigateUrl = string.Format("javascript:{0}(2);", WebRestClient.GetJSClientFunctionName(typeof(InfoPreviewHandler), "GetExtraInfo"));
            this.showExtraInfo2.NavigateUrl = WebRestClient.GetJSClientFunctionCall<InfoPreviewHandler>("GetExtraInfo", 235432);
            this.Session["mydata"] = "Hello, this is session data!";
            this.showSessionData.NavigateUrl = WebRestClient.GetJSClientFunctionCall(typeof(InfoPreviewHandler), "GetSessionData", "mydata");
            
            string link = WebRestClient.GetJSClientFunctionCall(typeof(InfoPreviewHandler), "GetSessionData", 33, 1, 's', "hello world", DateTime.Now);

            ////get a callback reference that can be use to deal with returned data, if applicable.
            //WebRestClient.RegisterJSCallback(typeof(InfoPreviewHandler), "GetExtraInfo", "callMyFunction(data);");

            //get a callback reference that can be use to deal with returned data, if applicable.
            WebRestClient.RegisterJSCallback(typeof(InfoPreviewHandler), "GetExtraInfo", Web.Enhancements.Rest.Templates.JavaScriptTemplateType.BasicAlert);

            WebRestClient.RegisterJSCallback(typeof(InfoPreviewHandler), "GetSessionData", Web.Enhancements.Rest.Templates.JavaScriptTemplateType.PopulateDivWithHtml, "infoBlock");

//            WebRestClient.RegisterJSCallback(typeof(InfoPreviewHandler), "GetSessionData", @"
//var block = document.getElementById('infoBlock');
////var inBlock = document.createElement('div');
////inBlock.innerHTML = '<span>'+data+'</span>';
////if (block.hasChildNodes())
////    block.removeChild(block.childNodes[0]);
////block.appendChild(inBlock);
//block.innerHTML = '<span>'+data+'</span>';
//");

            //InfoPreviewHandler info = new InfoPreviewHandler();
            //info.RegisterJSClient();

           // InfoPreviewHandler c; c.RegisterJSClient();
        }
    }
}